using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;

namespace Socialite
{
	[MonoTouch.Foundation.Register("LoginScreen")]
	public partial class LoginScreen : BaseTablessScreen
	{
		UIBarButtonItem _loginButton;
		
		NavigationControllerWithTab _homeNavigationController;
		NavigationControllerWithTab _searchNavigationController;
		NavigationControllerWithTab _mingleNavigationController;
		NavigationControllerWithTab _profileNavigationController;
		
		public LoginScreen () : base (UITableViewStyle.Grouped, null, true)
		{
			AccountInformation accountInfo = new AccountInformation ();
			var bctx = new BindingContext (null, accountInfo, "Login");
			Root = bctx.Root;
		}
		
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			_homeNavigationController = new NavigationControllerWithTab ("Hot");//, UITabBarSystemItem.HomeScreen homeScreen = new HomeScreen ();
			_homeNavigationController.PushViewController (NavigationLogic.WhatsHotPage, true);
					
			_searchNavigationController = new NavigationControllerWithTab ("Search");//, UITabBarSystemItem.SearchScreen searchScreen = new Search
			_searchNavigationController.PushViewController (NavigationLogic.SearchPage, true);
						
			_mingleNavigationController = new NavigationControllerWithTab ("Mingle");//, UITabBarSystemItem.MostViewed);
			_mingleNavigationController.PushViewController (NavigationLogic.MustCheckinPage, true);
						
			_profileNavigationController = new NavigationControllerWithTab ("Profile");//, UITabBarSystemItem.ProfileScreen profileScreen = new ProfileScreen ();
			_profileNavigationController.PushViewController (NavigationLogic.ProfilePage, true);			
			
			
			if (_loginButton == null)
				_loginButton = new UIBarButtonItem (
					"Log in",
					UIBarButtonItemStyle.Done,
					(sender, args) => 
				{		
					TabBarController.ViewControllers = new UIViewController [] {
						_homeNavigationController,
						_searchNavigationController,
						_mingleNavigationController,
						_profileNavigationController
					};
					NavigationController.PopToRootViewController(true);
				});
			
			NavigationController.TopViewController.NavigationItem.SetRightBarButtonItem (_loginButton, true);
		} 
	}
}
